import 'package:baselib/utils/image_util.dart';
import 'package:baselib/utils/log_util.dart';
import 'package:baselib/utils/time_util.dart';
import 'package:baselib/widgets/comm_app_bar.dart';
import 'package:baselib/widgets/comm_click_widget.dart';
import 'package:baselib/widgets/comm_password_textfield.dart';
import 'package:baselib/widgets/comm_textfield.dart';
import 'package:baselib/widgets/gradient_card_view.dart';
import 'package:baselib/widgets/gradient_text_widget.dart';
import 'package:baselib/widgets/inkwell_button.dart';
import 'package:baselib/widgets/nosize_app_bar.dart';
import 'package:baselib/widgets/simple_button.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:framelib/config/api_config.dart';
import 'package:framelib/utils/agora_sdk_util.dart';
import 'package:framelib/utils/color_util.dart';
import 'package:framelib/utils/drawable_util.dart';
import 'package:framelib/utils/nim_sdk_util.dart';
import 'package:framelib/utils/px_util.dart';
import 'package:framelib/utils/string_util.dart';
import 'package:framelib/widgets/comm_widget_manager.dart';
import 'package:framelib/widgets/main_gradient_button.dart';
import 'package:framelib/widgets/page_widget.dart';
import 'package:framelib/widgets/voice_grade_widget.dart';
import 'package:get/get.dart';
import 'package:module_business/module_comm/model/user_entity.dart';
import 'package:module_business/module_comm/model/user_params_model.dart';
import 'package:module_business/module_comm/viewmodel/login_email_view_model.dart';
import 'package:module_business/module_comm/viewmodel/register_info_view_model.dart';
import 'package:module_business/module_comm/viewmodel/register_select_favorite_view_model.dart';
import 'package:module_business/module_comm/viewmodel/register_view_model.dart';
import 'package:module_business/module_index/model/voice_person_entity.dart';
import 'package:module_business/module_index/viewmodel/my_room_view_model.dart';
import 'package:nim_core/nim_core.dart';

import 'package:agora_rtc_engine/agora_rtc_engine.dart';
/**
 * 我的房间主页
 */
class MyRoomPage extends GetWidget<MyRoomViewModel> {
  @override
  Widget build(BuildContext context) {
    return PageWidget.build(builder: (MyRoomViewModel model) {
      return WillPopScope(
          onWillPop: ()=>model.toRoomClose(),
          child: PageWidget.PageScaffoldWidget(
            isShowBg: true,
            appBar: CommAppBar(
              backgroundColor: ColorUtil.instance.color_transparent,
              leadingWidth: PxUtil.instance.screenWidth,
              leading: Container(
                padding: EdgeInsets.only(
                  left: PxUtil.instance.px_12,
                  right: PxUtil.instance.px_6,
                ),
                child: Row(
                  children: [
                    CommWidgetManager.buildCicleImagWidget(
                      model.roomInfo?.coverImg ?? '',
                      placeholder: DrawableUtil.instance.icon_default_head,
                      width: PxUtil.instance.px_42,
                      height: PxUtil.instance.px_42,
                      roundRadius: PxUtil.instance.px_21,
                      backgroundColor: ColorUtil.instance.color_f2f2f2,
                      padding: EdgeInsets.only(),
                      margin: EdgeInsets.only(),
                    ),
                    SizedBox(
                      width: PxUtil.instance.px_10,
                    ),
                    Expanded(
                        child: Column(
                          crossAxisAlignment: CrossAxisAlignment.start,
                          mainAxisAlignment: MainAxisAlignment.center,
                          children: [
                            Text(
                              model.roomInfo?.roomName,
                              style: TextStyle(
                                  color: ColorUtil.instance.color_white,
                                  fontSize: PxUtil.instance.px_10,
                                  fontWeight: FontWeight.w500),
                            ),
                            Text(
                              '${StringUtil.instance.ID}：${model.roomInfo?.roomCode}',
                              style: TextStyle(
                                color: ColorUtil.instance.color_white,
                                fontSize: PxUtil.instance.px_10,
                              ),
                            ),
                            Text(
                              '${model.roomInfo?.roomSynopsis ?? ''}',
                              style: TextStyle(
                                color: ColorUtil.instance.color_white,
                                fontSize: PxUtil.instance.px_9,
                              ),
                            )
                          ],
                        )),
                    //收藏
                    InkWellButton(
                      onPressed: ()=>model.doCollectRoom(),
                      child: Obx(()=>Container(
                        padding: EdgeInsets.all(PxUtil.instance.px_6),
                        child: ImagesUtil.loadAssetImage(
                            DrawableUtil.instance.icon_room_unfollow,
                            width: PxUtil.instance.px_22,
                            color: model.isCollect.value?ColorUtil.instance.color_main:ColorUtil.instance.color_white
                        ),
                      ))
                    ),
                    //设置
                    GestureDetector(
                      onTap: ()=>model.toRoomSet(),
                      child: Container(
                        padding: EdgeInsets.all(PxUtil.instance.px_6),
                        child: ImagesUtil.loadAssetImage(
                          DrawableUtil.instance.icon_room_set,
                          width: PxUtil.instance.px_22,
                        ),
                      ),
                    ),
                    //关闭
                    GestureDetector(
                      onTap: ()=>model.toRoomClose(),
                      child: Container(
                        padding: EdgeInsets.all(PxUtil.instance.px_6),
                        child: ImagesUtil.loadAssetImage(
                          DrawableUtil.instance.icon_room_close,
                          width: PxUtil.instance.px_22,
                        ),
                      ),
                    ),
                  ],
                ),
              ),
              // onActionPressed: ()=>model.toSkip(),
            ),
            body: Container(
              width: PxUtil.instance.screenWidth,
              height: PxUtil.instance.screenHeight -
                  PxUtil.instance.statusBarHeight -
                  PxUtil.instance.appBarHeight,
              padding: EdgeInsets.only(
                left: PxUtil.instance.px_12,
                right: PxUtil.instance.px_12,
              ),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  //视频区
                  // Visibility(
                  //   visible: true,
                  //     child: Container(
                  //   width: PxUtil.instance.screenWidth,
                  //   height: 200,
                  //   child: Stack(
                  //     children: [
                  //       FutureBuilder<bool>(
                  //           future: model.initStatus,
                  //           builder: (context, snap) {
                  //             if (snap.data != true) {
                  //               return Center(
                  //                 child: new Text(
                  //                   "初始化ing",
                  //                   style: TextStyle(fontSize: 30),
                  //                 ),
                  //               );
                  //             }
                  //             return AgoraVideoView(
                  //               controller: model.currentController,
                  //             );
                  //           }),
                  //       Align(
                  //         alignment: Alignment.topLeft,
                  //         child: SingleChildScrollView(
                  //           scrollDirection: Axis.horizontal,
                  //           child: Row(
                  //             ///增加点击切换
                  //             children: List.of(model.remoteControllers.entries.map(
                  //                   (e) => InkWell(
                  //                 onTap: ()=>model.onItemViewTap(e),
                  //                 child: SizedBox(
                  //                   width: 120,
                  //                   height: 120,
                  //                   child: AgoraVideoView(
                  //                     controller: e.value,
                  //                   ),
                  //                 ),
                  //               ),
                  //             )),
                  //           ),
                  //         ),
                  //       )
                  //     ],
                  //   ),
                  // )),
                  //成员
                  Container(
                    // height: PxUtil.instance.px_88,
                    margin: EdgeInsets.only(
                      top: PxUtil.instance.px_16,
                      bottom: PxUtil.instance.px_6,
                    ),
                    child: GridView.builder(
                        shrinkWrap: true,
                        padding: EdgeInsets.only(
                          // left: PxUtil.instance.px_20,
                          // right: PxUtil.instance.px_20,
                        ),
                        gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
                            crossAxisCount: 4,
                            mainAxisSpacing:5,
                            crossAxisSpacing: 0,
                            childAspectRatio: 1
                        ),
                        itemCount: (model.defaultPersons??[]).length ?? 0,
                        itemBuilder: (BuildContext context, int index) {
                          VoicePersonEntity voicePerson = model.defaultPersons[index];

                          return Container(
                            child: Column(
                              mainAxisSize: MainAxisSize.min,
                              crossAxisAlignment: CrossAxisAlignment.center,
                              children: [
                                Container(
                                  width: PxUtil.instance.px_66,
                                  height: PxUtil.instance.px_66,
                                  child: ((voicePerson?.yxAccid??'').isNotEmpty||(model.isRoomCreator(voicePerson?.identityType)))?
                                  //已经上麦
                                  GestureDetector(
                                    onTap: ()=>model.onUpWheatPersonPositionTap(index,voicePerson),
                                    child: Stack(
                                      alignment: Alignment.center,
                                      children: [
                                        CommWidgetManager.buildCicleImagWidget(
                                          voicePerson?.icon ?? '',
                                          placeholder:
                                          DrawableUtil.instance.icon_default_head,
                                          width: PxUtil.instance.px_56,
                                          height: PxUtil.instance.px_56,
                                          roundRadius: PxUtil.instance.px_28,
                                          backgroundColor: ColorUtil.instance.color_f2f2f2,
                                          padding: EdgeInsets.only(),
                                          margin: EdgeInsets.only(),
                                        ),
                                        Positioned(
                                            bottom: PxUtil.instance.px_0,
                                            left: PxUtil.instance.px_15,
                                            right: PxUtil.instance.px_15,
                                            child: GradientCardView(
                                              elevation: PxUtil.instance.px_0,
                                              alignment: Alignment.center,
                                              margin: EdgeInsets.only(),
                                              padding: EdgeInsets.only(),
                                              borderRadius: BorderRadius.circular(PxUtil.instance.px_2),
                                              child: Container(
                                                child: Text(
                                                  '${(voicePerson?.charisma??0)>999?'999+':(voicePerson?.charisma??0)}',
                                                  style: TextStyle(
                                                      fontSize: PxUtil.instance.px_8,
                                                      color: ColorUtil.instance.color_white
                                                  ),
                                                ),
                                              ),
                                            )
                                        ),
                                        Positioned(
                                            right: PxUtil.instance.px_0,
                                            bottom: PxUtil.instance.px_10,
                                            child: Obx(()=>VoiceGradeWidget(
                                              // isCloseWheat: (voicePerson?.isCloseWheat??false),
                                              isCloseWheat: model.isCloseWheat(voicePerson),
                                              volume: model.getCurrAgoraPerson(voicePerson)?.volume,
                                            ))
                                        )
                                      ],
                                    ),
                                  ):
                                  //没有上麦
                                  GestureDetector(
                                    onTap: ()=>model.onUnUpWheatPersonPositionTap(index,voicePerson),
                                    child: Stack(
                                      alignment: Alignment.center,
                                      children: [
                                        Container(
                                          width: PxUtil.instance.px_56,
                                          height: PxUtil.instance.px_56,
                                          decoration: BoxDecoration(
                                              borderRadius: BorderRadius.circular(PxUtil.instance.px_28,),
                                              color: ColorUtil.instance.color_2EFFFFFF
                                          ),
                                          child: Center(
                                            child: ImagesUtil.loadAssetImage(
                                                (voicePerson?.lockFlag==1)?
                                                DrawableUtil.instance.icon_portrait_wihte_lock:
                                                DrawableUtil.instance.icon_portrait_wihte_add,
                                                width: PxUtil.instance.px_20,
                                                fit: BoxFit.fitWidth
                                            ),
                                          ),
                                        ),
                                      ],
                                    ),
                                  )
                                  ,
                                ),
                                Expanded(child: Column(
                                  mainAxisAlignment: MainAxisAlignment.center,
                                  children: [
                                    Text(
                                      voicePerson?.nickname ?? 'Mic ${index}',
                                      style: TextStyle(
                                          fontSize: PxUtil.instance.px_12,
                                          color: ColorUtil.instance.color_white),
                                    )
                                  ],
                                ))
                              ],
                            ),
                          );
                        }),
                  ),
                  //公告
                  Obx(() => ("${model?.roomYxInfo.value.announcement??''}").isEmpty?SizedBox(width: PxUtil.instance.px_0,):
                  Container(
                    margin: EdgeInsets.only(
                      top: PxUtil.instance.px_16,
                    ),
                    width: PxUtil.instance.screenWidth * 3 / 4,
                    decoration: BoxDecoration(
                        gradient: LinearGradient(
                          begin: Alignment.topCenter,
                          end: Alignment.bottomCenter,
                          colors: [
                            ColorUtil.instance.color_cc5C40A8,
                            ColorUtil.instance.color_4d5C40A8,
                          ],
                        ),
                        borderRadius: BorderRadius.circular(PxUtil.instance.px_10)),
                    padding: EdgeInsets.all(PxUtil.instance.px_12),
                    child: Column(
                      mainAxisSize: MainAxisSize.min,
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Container(
                          child: GradientTextWidget(
                            txt: '[${StringUtil.instance.warm_tips}]',
                            txtStyle: TextStyle(
                                fontSize: PxUtil.instance.px_11,
                                fontWeight: FontWeight.bold,
                                color: ColorUtil.instance.color_white),
                            gradient: LinearGradient(colors: [
                              ColorUtil.instance.color_B6359C,
                              ColorUtil.instance.color_EF0A6A,
                            ]),
                          ),
                        ),
                        SizedBox(
                          height: PxUtil.instance.px_8,
                        ),
                        Text(
                          "${model?.roomYxInfo.value.announcement??''}",
                          style: TextStyle(
                            fontSize: PxUtil.instance.px_11,
                            color: ColorUtil.instance.color_white,
                          ),
                        )
                      ],
                    ),
                  )),
                  //人员进入、人员退出、送礼等
                  Obx(() => (model.attachmentMemberMessages.value??[]).isEmpty?SizedBox(width: PxUtil.instance.px_0,):
                  Container(
                    margin: EdgeInsets.only(
                      top: PxUtil.instance.px_10,
                    ),
                    constraints: BoxConstraints(
                      maxHeight: PxUtil.instance.px_80,
                      maxWidth: PxUtil.instance.screenWidth * 3 / 4,
                    ),
                    child: _buildMiddleMemberStatusContUi(model),
                  )),
                  //中间聊天内容
                  Expanded(
                      child: Container(
                        margin: EdgeInsets.only(
                          top: PxUtil.instance.px_10,
                          bottom: PxUtil.instance.px_10,
                        ),
                        child: _buildMiddleContUi(model),
                      )),
                  //底部栏
                  // Obx(() => Visibility(
                  //     visible: model.isCommentOpen.isTrue,
                  //     child: Container(
                  //       width: PxUtil.instance.screenWidth,
                  //       margin: EdgeInsets.only(
                  //         bottom: PxUtil.instance.px_10,
                  //         top: PxUtil.instance.px_0,
                  //       ),
                  //       child: Row(
                  //         children: [
                  //           Expanded(
                  //               child: Container(
                  //                 height: PxUtil.instance.px_36,
                  //                 alignment: Alignment.centerLeft,
                  //                 decoration: BoxDecoration(
                  //                     color: ColorUtil.instance.color_677294,
                  //                     borderRadius:
                  //                     BorderRadius.circular(PxUtil.instance.px_18)),
                  //                 child: TextField(
                  //                   style: TextStyle(
                  //                       color: ColorUtil.instance.color_white
                  //                   ),
                  //                   enabled: true,
                  //                   textAlign: TextAlign.start,
                  //                   maxLength: 200,
                  //                   maxLines: 1,
                  //                   textInputAction: TextInputAction.done,
                  //                   keyboardType: TextInputType.text,
                  //                   // autofocus: true,
                  //                   focusNode: model.commitFocusNode,
                  //                   // controller: model.commitTextController,
                  //                   onChanged: (value)=>model.onCommentChanged(value),
                  //                   cursorColor: ColorUtil.instance.color_white,
                  //                   decoration: InputDecoration(
                  //                       contentPadding: EdgeInsets.only(
                  //                         left: PxUtil.instance.px_15,
                  //                         right: PxUtil.instance.px_15,
                  //                         bottom: PxUtil.instance.px_0,
                  //                       ),
                  //                       isDense: true,
                  //                       counterText: "",
                  //                       focusedBorder: UnderlineInputBorder(
                  //                           borderSide: BorderSide(
                  //                               color: ColorUtil
                  //                                   .instance.color_transparent,
                  //                               width: 1)),
                  //                       enabledBorder: UnderlineInputBorder(
                  //                           borderSide: BorderSide(
                  //                               color: ColorUtil
                  //                                   .instance.color_transparent,
                  //                               width: 1))),
                  //                 ),
                  //               )),
                  //           Container(
                  //             margin: EdgeInsets.only(
                  //                 left: PxUtil.instance.px_15
                  //             ),
                  //             child: GestureDetector(
                  //               onTap: ()=>model.sendMsg(),
                  //               child: ImagesUtil.loadAssetImage(
                  //                   DrawableUtil.instance.icon_send,
                  //                   height: PxUtil.instance.px_30,
                  //                   fit: BoxFit.fitHeight
                  //               ),
                  //             ),
                  //           )
                  //         ],
                  //       ),
                  //     )
                  // )),
                  // Obx(()=>Visibility(
                  //     visible: !model.isCommentOpen.isTrue,
                  //     child:
                      Container(
                        width: PxUtil.instance.screenWidth,
                        height: PxUtil.instance.px_60,
                        padding: EdgeInsets.only(
                          left: PxUtil.instance.px_19,
                          right: PxUtil.instance.px_19,
                          bottom: PxUtil.instance.px_19,
                        ),
                        child: Row(
                          children: [
                            (!model.isUpWheat(model.currVoicePersonEntity))?SizedBox(width: PxUtil.instance.px_0,):
                            Container(
                              margin: EdgeInsets.only(
                                right: PxUtil.instance.px_16
                              ),
                              child: model.isSelfLimitedSpeak()?
                              ImagesUtil.loadAssetImage(
                                DrawableUtil.instance.icon_room_voice_speak_close,
                                width: PxUtil.instance.px_32,
                              ):
                              Obx(() => InkWellButton(
                                onPressed: ()=>model.adjustSpeakVolume(),
                                child: ImagesUtil.loadAssetImage(
                                  model.speakRecordOpen.value?
                                  DrawableUtil.instance.icon_room_voice_speak_open
                                      :DrawableUtil.instance.icon_room_voice_speak_close,
                                  width: PxUtil.instance.px_32,
                                ),
                              )),
                            ),

                            Obx(() => InkWellButton(
                              onPressed: ()=>model.adjustVolume(),
                              child: Container(
                                child: ImagesUtil.loadAssetImage(
                                  (model.voiceListenOpen.value??false)?
                                  DrawableUtil.instance.icon_room_voice_listen_open:
                                  DrawableUtil.instance.icon_room_voice_listen_close,
                                  width: PxUtil.instance.px_32,
                                ),
                              ),
                            )),
                            Expanded(
                                child: Center(
                                  child: InkWellButton(
                                    onPressed: ()=>model.onOpenGifts(),
                                    child: Container(
                                      child: ImagesUtil.loadAssetImage(
                                        DrawableUtil.instance.icon_room_gifts,
                                        width: PxUtil.instance.px_36,
                                      ),
                                    ),
                                  ),
                                )),
                            InkWellButton(
                              onPressed: () => model.onCommentTap(),
                              child: Container(
                                child: ImagesUtil.loadAssetImage(
                                  DrawableUtil.instance.icon_room_comment,
                                  width: PxUtil.instance.px_32,
                                ),
                              ),
                            ),
                          ],
                        ),
                      )
                  // )),
                ],
              ),
            ),
          ),
      );
    });
  }
  // // 生成远端视频
  // Widget _remoteVideo(MyRoomViewModel model) {
  //   if (model.remoteUid != null) {
  //     return AgoraVideoView(
  //       controller: VideoViewController.remote(
  //         rtcEngine: AgoraSDKUtil.engine,
  //         canvas: VideoCanvas(uid: model.remoteUid),
  //         connection: RtcConnection(channelId: '${model.roomYxInfo.value.roomId}'),
  //       ),
  //     );
  //   } else {
  //     return const Text(
  //       'Please wait for remote user to join',
  //       textAlign: TextAlign.center,
  //     );
  //   }
  // }
  _buildMiddleContUi(MyRoomViewModel model) {
    return Obx(() => ListView.builder(
        shrinkWrap: true,
        reverse: true,
        itemCount: model.chatRoomMsgs.value.length??0,
        itemBuilder: (BuildContext context,int index){
          var chatRoomMsg = model.chatRoomMsgs.value[index];
          var fromAccount = chatRoomMsg?.fromAccount;
          // final NIMChatroomMember user = model.chatRoomMembers.firstWhere((
          //     element) => element.account == fromAccount,
          //     orElse: () => new NIMChatroomMember());
          final UserEntity userEntity = model.chatRoomServiceMembers.firstWhere((
              element) => element.yxAccid == fromAccount,
              orElse: () => new UserEntity());
          LogUtil.d('NIMSDKUtil--->user,model.userEntity=${userEntity?.toJson()},');
          LogUtil.d('NIMSDKUtil--->user,model.fromAccount=${fromAccount},');
          LogUtil.d('NIMSDKUtil--->user,model.chatRoomServiceMembers=${model.chatRoomServiceMembers.map((e) => e?.toJson()).toList()},');
          // LogUtil.d('NIMSDKUtil--->user,icon=${user?.avatar},nickname=${user?.nickname},');
          // LogUtil.d('NIMSDKUtil--->userEntity,icon=${userEntity?.icon},nickname=${userEntity?.nickname},');
          // LogUtil.d('NIMSDKUtil--->fromNickname=${chatRoomMsg?.fromNickname},content=${chatRoomMsg?.content},');
          return Container(
            width: PxUtil.instance.screenWidth*3/4,
            margin: EdgeInsets.only(
              bottom: PxUtil.instance.px_16
            ),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: <Widget>[
                Row(
                  children: [
                    GestureDetector(
                      onTap: ()=>model.onSpeekPersonPositionTap(index,userEntity),
                      child: Container(
                          margin: EdgeInsets.only(
                              right: PxUtil.instance.px_12
                          ),
                          child:
                          CommWidgetManager.buildCicleImagWidget(
                            userEntity?.icon ?? '',
                            placeholder:
                            DrawableUtil.instance.icon_default_head,
                            width: PxUtil.instance.px_28,
                            height: PxUtil.instance.px_28,
                            roundRadius: PxUtil.instance.px_14,
                            backgroundColor: ColorUtil.instance.color_f2f2f2,
                            padding: EdgeInsets.only(),
                            margin: EdgeInsets.only(),
                          )
                      ),
                    ),
                    Text(
                      '${userEntity?.nickname??''}',
                      style: TextStyle(
                          fontSize: PxUtil.instance.px_13,
                          color: ColorUtil.instance.color_white
                      ),
                    ),
                    SizedBox(width:  PxUtil.instance.px_8,),
                    Text(
                      '${TimeUtils.forMatTimeByMs(chatRoomMsg?.timestamp,format: 'yyyy-MM-dd HH:mm:ss')}',
                      style: TextStyle(
                          fontSize: PxUtil.instance.px_8,
                          color: ColorUtil.instance.color_white
                      ),
                    )
                  ],
                ),
                Container(
                  margin: EdgeInsets.only(
                      top: PxUtil.instance.px_6
                  ),
                  padding: EdgeInsets.only(
                    left: PxUtil.instance.px_9,
                    right: PxUtil.instance.px_9,
                    top: PxUtil.instance.px_5,
                    bottom: PxUtil.instance.px_5,
                  ),
                  decoration: BoxDecoration(
                    borderRadius: BorderRadius.circular(PxUtil.instance.px_10),
                    color: ColorUtil.instance.color_26000000
                  ),
                  child: Text(
                    '${chatRoomMsg?.content??''}',
                    style: TextStyle(
                        fontSize: PxUtil.instance.px_9,
                        color: ColorUtil.instance.color_white
                    ),
                  )
                ),
                // chatRoomMsg.messageType == NIMMessageType.image
                //     ? Picture(data)
                //     : data.messageType == NIMMessageType.audio
                //     ? Voice(data)
                //     : ChatText(data),

              ],
            ),
          );
        }
    ));
  }
  _buildMiddleMemberStatusContUi(MyRoomViewModel model) {
    return ListView.builder(
        shrinkWrap: true,
        reverse: true,
        itemCount: model.attachmentMemberMessages.value.length??0,
        itemBuilder: (BuildContext context,int index){
          var attachmentMemberMsg = model.attachmentMemberMessages.value[index];
          if(attachmentMemberMsg.type== NIMChatroomNotificationTypes.chatRoomMemberIn){
            //人员进入
            return _buildMemberInRoomUi(attachmentMemberMsg?.fromNickName);
          }else if(attachmentMemberMsg.type== NIMChatroomNotificationTypes.chatRoomMemberExit){
            //人员退出
            return _buildMemberLeaveRoomUi(attachmentMemberMsg?.fromNickName);
          }else if(attachmentMemberMsg.type== NIMChatroomNotificationTypes.chatRoomClose){
            //房间被关闭
            return _buildCloseRoomUi();
          }else if(attachmentMemberMsg.type== 600){
            //送礼
            return _buildGiftsPointUi(
              fromNickName: attachmentMemberMsg?.fromNickName,
              toNickName: attachmentMemberMsg?.toNickName,
              giftNum: attachmentMemberMsg?.giftNum,
              giftImg: attachmentMemberMsg?.giftSmallImg
            );
          }
          return SizedBox(width: PxUtil.instance.px_0,);
        }
    );
  }
  //人员进入
  _buildMemberInRoomUi(nickName){
    return Row(
      children: [
        Container(
          margin: EdgeInsets.only(top: PxUtil.instance.px_12),
          decoration: BoxDecoration(
              borderRadius: BorderRadius.circular(PxUtil.instance.px_15),
              color: ColorUtil.instance.color_33FFF600),
          padding: EdgeInsets.only(
            left: PxUtil.instance.px_12,
            right: PxUtil.instance.px_12,
            top: PxUtil.instance.px_5,
            bottom: PxUtil.instance.px_5,
          ),
          child: RichText(
              text: TextSpan(
                  text: StringUtil.instance.Welcome,
                  style: TextStyle(
                    fontSize: PxUtil.instance.px_11,
                    color: ColorUtil.instance.color_white,
                  ),
                  children: [
                    TextSpan(
                      text: ' ${nickName??''} ',
                      style: TextStyle(
                        fontSize: PxUtil.instance.px_11,
                        color: ColorUtil.instance.color_FFF600,
                      ),
                    ),
                    TextSpan(
                      text: StringUtil.instance.into_the_room,
                      style: TextStyle(
                        fontSize: PxUtil.instance.px_11,
                        color: ColorUtil.instance.color_white,
                      ),
                    )
                  ])),
        )
      ],
    );
  }
  //人员退出
  _buildMemberLeaveRoomUi(nickName){
    return Row(
      children: [
        Container(
          margin: EdgeInsets.only(top: PxUtil.instance.px_12),
          decoration: BoxDecoration(
              borderRadius: BorderRadius.circular(PxUtil.instance.px_15),
              color: ColorUtil.instance.color_33FFF600),
          padding: EdgeInsets.only(
            left: PxUtil.instance.px_12,
            right: PxUtil.instance.px_12,
            top: PxUtil.instance.px_5,
            bottom: PxUtil.instance.px_5,
          ),
          child: RichText(
              text: TextSpan(
                  text: '${nickName??''} ',
                  style: TextStyle(
                    fontSize: PxUtil.instance.px_11,
                    color: ColorUtil.instance.color_FFF600,
                  ),
                  children: [
                    TextSpan(
                      text: StringUtil.instance.leave_the_room,
                      style: TextStyle(
                        fontSize: PxUtil.instance.px_11,
                        color: ColorUtil.instance.color_white,
                      ),
                    )
                  ])),
        )
      ],
    );
  }
  //关闭房间
  _buildCloseRoomUi(){
    return Row(
      children: [
        Container(
          margin: EdgeInsets.only(top: PxUtil.instance.px_12),
          decoration: BoxDecoration(
              borderRadius: BorderRadius.circular(PxUtil.instance.px_15),
              color: ColorUtil.instance.color_33FFF600),
          padding: EdgeInsets.only(
            left: PxUtil.instance.px_12,
            right: PxUtil.instance.px_12,
            top: PxUtil.instance.px_5,
            bottom: PxUtil.instance.px_5,
          ),
          child: RichText(
              text: TextSpan(
                text: StringUtil.instance.the_room_be_closed,
                style: TextStyle(
                  fontSize: PxUtil.instance.px_11,
                  color: ColorUtil.instance.color_white,
                ),)),
        )
      ],
    );
  }
  //送礼
  _buildGiftsPointUi({String fromNickName,String toNickName,String giftImg,int giftNum}){
    return //送礼
      Row(
        children: [
          Container(
            margin: EdgeInsets.only(top: PxUtil.instance.px_12),
            decoration: BoxDecoration(
                borderRadius: BorderRadius.circular(PxUtil.instance.px_15),
                color: ColorUtil.instance.color_33FFF600),
            padding: EdgeInsets.only(
              left: PxUtil.instance.px_12,
              right: PxUtil.instance.px_12,
              top: PxUtil.instance.px_5,
              bottom: PxUtil.instance.px_5,
            ),
            child: RichText(
                text: TextSpan(
                    text: '${fromNickName??''} ',
                    style: TextStyle(
                      fontSize: PxUtil.instance.px_11,
                      color: ColorUtil.instance.color_FFF600,
                    ),
                    children: [
                      TextSpan(
                        text: StringUtil.instance.send_to,
                        style: TextStyle(
                          fontSize: PxUtil.instance.px_11,
                          color: ColorUtil.instance.color_white,
                        ),
                      ),
                      TextSpan(
                        text: ' ${toNickName??''} ',
                        style: TextStyle(
                          fontSize: PxUtil.instance.px_11,
                          color: ColorUtil.instance.color_FFF600,
                        ),
                      ),
                      //礼物
                      WidgetSpan(
                          child: ImagesUtil.loadNetworkImage(
                            giftImg,
                            width: PxUtil.instance.px_24,
                          )),
                      TextSpan(
                        text: ' X${giftNum??0}',
                        style: TextStyle(
                          fontSize: PxUtil.instance.px_11,
                          color: ColorUtil.instance.color_white,
                        ),
                      ),
                    ])),
          )
        ],
      );
  }
}
